feat: port entity schema to gen-schema#563
Draft
sini wants to merge 18 commits into
Draft
Conversation
6574fac to
a370d30
Compare
b2bcfd4 to
1b56211
Compare
20fedec to
91ded60
Compare
Replaces hand-rolled schemaEntryType with gen-schema mkSchemaOption. Sidecars: includes, excludes. Computed: isEntity (structural content only). Extracts resolvedCtxModule (id_hash, resolved, collisionPolicy) to _types.nix for entity type reuse. collisionPolicy flows through deferred module merge to entity instances (not a sidecar) preserving existing ctx.host.collisionPolicy resolution path.
den.hosts now accepts both forms:
- Legacy: den.hosts.x86_64-linux.igloo = { ... }
- Flat: den.hosts.igloo = { system = "x86_64-linux"; ... }
The outer option type uses a permissive submodule with deepMergeAttrs
freeformType (lib.recursiveUpdate-based merge that avoids the infinite
recursion lib.types.anything causes with cross-option references).
The apply function preprocesses flat entries into two-level form and
re-evaluates through the original attrsOf systemType, so all 6
consumers see the canonical { system.name = hostConfig } shape.
Same pattern as den.hosts: deepMergeAttrs + preprocessHosts + apply. Cross-entity host lookup and osConfig injection preserved.
Covers: id_hash, freeform, topology, meta introspection, isEntity computed, schema includes sidecar.
Update flake inputs and references to match the renamed repo at github:sini/gen-schema.
gen-schema flattened _meta into _-prefixed options and renamed sidecars → collections. nix-effects changed bindAttrs so true is a literal param, not an optionality marker — translate __args values to fx.bind.optionalArg before bind.fn.
Build host/user/home submodules with gen-schema's mkInstanceType, which injects name, strict/freeform, _module.args.<kind>, and schema-owned id_hash (gen-algebra mkIdentityModule) — replacing the hand-rolled id_hash reflection in resolvedCtxModule. Identity now shares the exact algorithm gen-schema's ref/setOf dedup compares against, removing the drift hazard between den's copy and the library's. Add an entity-gen-schema test pinning _roots: host is a root scope and user/home are not (the buildRoots root-detection contract).
den.reservedKeys fed structuralKeysSet, which the pipeline classifier and the synthetic-_ childKeys filter honored — but the aspect submodule's freeform value type (aspectKeyType) wrapped every undeclared key into the __contentValues/__provider provenance shape regardless. A reserved key was excluded from dispatch but its value was still mangled, so consumers could not read it back as the metadata den.reservedKeys promises. Route structural/reserved keys through a passthrough merge (last def wins) in aspectKeyType — the per-key dispatch the type comment already anticipated. den.aspects.<name>.<reservedKey> now returns the raw value.
91ded60 to
a22c657
Compare
The `self` dispatch guard (fire-once at the registration scope; always bound in ctx so flake-scope resolution policies can fire) was added on this branch but never made it into origin/main's squash of the cherry-picked fixes — denful#603 covered spawn subtree routes and multi-def identity, not `self`. Rebasing onto origin/main therefore silently dropped it. Without `self`, `{ self, ... }:` policies never dispatch (flake isn't bound in its own ctx), collapsing any flake-scope resolution cascade — e.g. a consumer's flake -> fleet -> environment -> host walk produces zero host outputs. Re-applies the dispatch.nix `self` injection and the policy/schema.nix late-fan-out exclusion, plus the self-guard regression test.
schema-util and entities/_types each hand-rolled `filter (k != "conf" && !hasPrefix "_")` over `attrNames den.schema`. gen-schema already exposes `_kindNames` (sorted, _-prefixed introspection keys excluded), so consume that as the canonical kind list and drop the duplicated _-prefix filtering. Entity detection still uses the schema's `isEntity` collection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
schemaEntryTypeinoptions.nixwith gen-schema'smkSchemaOption(sidecars:includes,excludes; computed:isEntity)_topologyand_metaintrospection from gen-schemaresolvedCtxModuleto shared_types.nixfor reuse across entity typesDetails
Schema port:
den.schemanow uses gen-schema'smkSchemaEntryTypewhich provides sidecar extraction, computed fields, and__functorwrapping. TheresolvedCtxModule(id_hash, resolved, collisionPolicy) is extracted to_types.nixand injected into entity submodule imports.Flat form: Both
den.hostsandden.homesnow accept flat declarations:A
deepMergeAttrscustom type accepts both forms, andapplypreprocesses flat entries into the canonical two-level shape viapreprocessHosts. All 6 consumers see the unchanged{ system.name = entity }shape.Tests: 18 new tests (843 total, up from 825) covering flat hosts, flat homes, id_hash, freeform attrs, topology, meta introspection, isEntity computed, and schema sidecars.
Test plan
nix develop -c just ci)default,minimal,example) unaffected